<?php

namespace App\Admin\Controllers;

use App\Admin\Controllers\Traits\WxSettingTraits\formAdminTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formAdTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formApiTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formAppTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formAvatarFrameTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formCircleTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formCoinTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formContentsTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formDivideTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formEmojiTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formFrontTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formGroupPushTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formMiniTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formOssTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPageFindTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPageIndexTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPageMineTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPageNoticeTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPageSearchTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPageVipTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPayTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPcTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPagePublishTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formPostTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formRobotTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formSafeTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formSeoTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formShopTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formTaokeTrait;
use App\Admin\Controllers\Traits\WxSettingTraits\formTrait;
use Dcat\Admin\Widgets\Form;

class WxSettingController extends Form
{
    use formTrait,formPayTrait,formAppTrait,formOssTrait,formMiniTrait,formPcTrait, formSafeTrait, formApiTrait, formTaokeTrait,formPageMineTrait;
    use formPageIndexTrait,formSeoTrait,formRobotTrait,formPagePublishTrait,formContentsTrait,formAdminTrait,formCircleTrait,formAdTrait,formPageVipTrait;
    use formCoinTrait,formEmojiTrait,formPageNoticeTrait,formAvatarFrameTrait,formPostTrait,formFrontTrait,formShopTrait,formPageFindTrait,formPageSearchTrait,formGroupPushTrait,formDivideTrait;

    protected $options = [
        0 => '是',
        1 => '否',
    ];

    public function handle(array $input)
    {
        // $input是你接收到的表单数据
        // 在这里可以写你的处理逻辑
        // 第一个参数是响应的成功信息，第二个参数是要跳转的路由
        return $this->response()->success('Processed successfully.')->refresh();
    }

    public function _table_keyvalue_data(array $data){
        if(_empty_($data)){
            return json_encode([]);
        }
        $_data = [];
        foreach ($data as $row){
            if(_array_key($row, '_remove_', null) == 1){
                continue;
            }
            if(isset($row['_remove_'])){
                unset($row['_remove_']);
            }
            if(!is_array($row)) {
                $_data[] = $row;
                continue;
            }
            $row_ = [];
            foreach ($row as $key => $value){
                if(!is_array($value)){
                    $row_[$key] = $value;
                    continue;
                }
                unset($value['_def_']);
                if(!isset($value['keys']) && !isset($value['values'])){
                    $row_[$key] = $value;
                    continue;
                }
                $_value = [];
                if(isset($value['keys'][0])){
                    for($i = 0; $i < count($value['keys']); $i ++){
                        $_value[$value['keys'][$i]] = $value['values'][$i];
                    }
                }else{
                    for($i = 1; $i <= count($value['keys']); $i ++){
                        $_value[$value['keys'][$i]] = $value['values'][$i];
                    }
                }
                $row_[$key] = $_value;
            }
            $_data[] = $row_;
        }
        return json_encode($_data);
    }
}
